<template>
    <addEditEvReviewView ref="addEditEvReviewView" />
    <addFileView ref="addFileView" />
    <el-main>
        <div class="teacher">
            <div class="app-table">
                <div class="app-body">
                    <div class="app-search">
                        <el-form :inline="true" class="demo-form-inline" v-model="form">
                            <el-form-item label="评价类别">
                                <el-select clearable v-model="form.typeId" placeholder="请选择评价类别" style="width: 190px;">
                                    <el-option v-for=" item in typeList" :value="item.id" :label="item.name">
                                    </el-option>
                                </el-select>
                            </el-form-item>

                            <el-form-item label="标题">
                                <el-input placeholder="请输入评价标题" v-model="form.title"></el-input>
                            </el-form-item>
                            <el-form-item label="说明">
                                <el-input placeholder="请输入评价说明" v-model="form.brief"></el-input>
                            </el-form-item>

                            <el-form-item>
                                <el-button type="primary" @click="onSubmit" plain @keyup.enter="searchEnter">搜索
                                </el-button>
                                <!-- <el-button type="success" plain @click="add">添加</el-button> -->
                                <!-- <el-button type="warning" plain @click="exportExcel">导出报表</el-button> -->
                            </el-form-item>
                        </el-form>
                    </div>
                    <el-table size="small" :data="list" style="width: 100%" border :row-class-name="tableRowClassName">
                        <el-table-column prop="id" label="id" width="80px" />
                        <el-table-column prop="typeName" label="类别" />
                        <el-table-column prop="title" label="标题" />
                        <!-- <el-table-column prop="brief" label="简介" /> -->
                        <!-- <el-table-column prop="content" label="内容" /> -->
                        <!-- <el-table-column prop="startTime" label="开始时间" /> -->
                        <!-- <el-table-column prop="endTime" label="结束时间" /> -->
                        <el-table-column prop="sortNum" label="权重" />
                        <!-- <el-table-column prop="status" label="状态" /> -->
                        <el-table-column prop="createTime" label="创建时间" />
                        <el-table-column prop="createName" label="创建人" />
                        <el-table-column prop="createNumber" label="创建人工号" />
                        <el-table-column label="操作" width="210px">
                            <template style="display: block" #default="scope">

                                <el-button size="small" type="primary" @click="designEvReview(scope.row)">立即评价
                                </el-button>
                                <!-- <el-button size="small" type="warning" @click="exportEvReview(scope.row)">导出题目
                                </el-button> -->
                            </template>
                        </el-table-column>
                        <template v-slot:empty>
                            <el-empty description="暂无数据"></el-empty>
                        </template>
                    </el-table>
                    <el-config-provider :locale="locale">
                        <el-pagination :total="total" :page-size="limit" :page-sizes="[5, 10, 20, 30, 40, 50, 100]"
                            layout="total, sizes, prev, pager, next, jumper" @size-change="changePageSize"
                            @current-change="changeCurrentPage">
                        </el-pagination>
                    </el-config-provider>
                </div>
                <bottomView />
            </div>
        </div>
    </el-main>
</template>
<script>
import addEditEvReviewView from "@/components/evaluate/addEditEvReview.vue";
import addFileView from "@/components/addExcelFile.vue";
import { ElConfigProvider, ElMessageBox, ElMessage } from "element-plus";
import zhCn from "element-plus/lib/locale/lang/zh-cn";
import { httpService } from "@/utils/httpService";
import { Picture as IconPicture, Upload } from "@element-plus/icons-vue";
import bottomView from "@/components/bottom.vue";

export default {
    name: "EvReviewListView",
    data() {
        return {
            type: 0,
            title: "",
            page: 0,
            pageSize: 10,
            total: 0,
            limit: 10,
            list: [],
            typeList: [],
            form: {
                title: "",
                brief: "",
                content: "",
                createNumber: "",
                createName: "",
                typeId: "",
            },
        };
    },
    components: {
        addEditEvReviewView,
        addFileView,
        IconPicture,
        ElConfigProvider,
        ElMessageBox,
        ElMessage, Upload, bottomView,
    },
    setup() {
        return {
            locale: zhCn,
        };
    },
    mounted() {
        this.getEvReviewList();
        this.getEvTypeList();
    },
    watch: {
        $route() {
            this.getEvReviewList();
        },
    },
    methods: {
        searchEnter: function (e) {
            // 使用 which 和 keyCode 属性来解决兼容问题
            var keyCode = window.event ? e.keyCode : e.which;
            var val = e.target.value;
            if (keyCode == 13 && val) {
                this.getEvReviewList();
            }
        },

        designEvReview(obj) {
            let routeData = this.$router.resolve({
                name: "evReviewAddView",
                query: {
                    p: obj.id,
                },
            });
            window.open(routeData.href, "_blank");
        },


        reloadData() {
            this.page = 1;
            this.getEvReviewList()
        },
        getEvTypeList() {
            httpService(
                "/javaApi/evType/queryAll",
                {
                },
                "get"
            ).then((data) => {
                this.typeList = data;
            });
        },

        onSubmit() {
            this.getEvReviewList();
        },
        // 每页记录数改变，size：回调参数，表示当前选中的“每页条数”
        changePageSize(size) {
            this.pageSize = size;
            this.limit = size;
            this.getEvReviewList();
        },

        // 改变页码，page：回调参数，表示当前选中的“页码”
        changeCurrentPage(page) {
            this.page = page;
            this.getEvReviewList();
        },
        tableRowClassName({ row, rowIndex }) {
            return "";
        },
        getEvReviewList() {
            httpService(
                "/javaApi/evReview/listMy/" + this.page + "/" + this.pageSize,
                {
                    "title": this.form.title,
                    "brief": this.form.brief,
                    "content": this.form.content,
                    "createNumber": this.form.createNumber,
                    "typeId": this.form.typeId,
                    "createName": this.form.createName,
                },
                "get"
            ).then((data) => {
                this.list = data.list;
                this.total = data.total;
                this.pageCount = data.pages;
            });
        },
        exportEvReview(e) {
            httpService(
                "/javaApi/evReviewQuestion/exportExcel",
                {
                    "reviewId": e.id,
                },
                "get"
            ).then((data) => {
                if (data.code == 200) {
                    window.open(data.msg, '_blank')
                }
            });
        },
    },
};
</script>
<style scoped>
.el-main {
    padding: 0px;
}

.teacher-content {
    width: 100%;
}

.app-table {
    background: #eff3f5;
    padding: 10px;
}

.app-search {
    margin-top: 20px;
}

.app-separator {
    padding-top: 10px;
    padding-bottom: 20px;
    padding-left: 10px;
}

.app-body {
    background: white;
    padding: 20px 20px 10px 20px;
    margin-bottom: 10px;
    min-height: calc(100vh - 243px);
}

.el-table .warning-row {
    --el-table-tr-bg-color: var(--el-color-warning-lighter);
}

.el-table .success-row {
    --el-table-tr-bg-color: var(--el-color-success-lighter);
}

.el-pagination {
    text-align: center;
    margin-top: 10px;
}
</style>
